home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Network / PowerScript 14 / PowerScript RA < prev    next >
Encoding:
Text File  |  1999-03-04  |  19.5 KB  |  748 lines  |  [TEXT/ToyS]

  1. -- User setable properties
  2. property kasOpenWindowWhenRun : true -- Set to false to not open the remote item's window in the Finder when run
  3. property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
  4. property kasServerAlerts : true -- Set to false to stop warnings about missed servers
  5. property kasFinder : "Finder" -- name of application to open RemoteLaunchers
  6. property kasAppendage : " ->" -- Appended to file name if we can't use original
  7. property kasPrefixLauncher : "≈ " -- Prefix named of launchers with these characters.
  8. property kasJustDoIt : true -- Don't ask so many questions - just do it!
  9.  
  10. -- Internal/User setable globals
  11. property gasLinkSet : false -- Has the friend been asked for? - set to true to never ask
  12. property gasLinkNeed : false
  13. property kasLinkUserDft : "CasaVision" -- Defaults for linking access
  14. property kasLinkPassDft : ""
  15.  
  16. property gasServSet : false
  17. property gasServNeed : false
  18. property kasServUserDft : "Synapse" -- Defaults for server access
  19. property kasServPassDft : ""
  20. property kasServNTDft : ""
  21.  
  22. -- Internal globals
  23. global gasLinkUser -- Our friend on all machines
  24. global gasLinkPass -- Our friend's password on all machines
  25. global gasServUser -- Our friend on all machines
  26. global gasServPass -- Our friend's password on all machines
  27. global gasServNT -- Volume password
  28.  
  29. property gasOurAlias : "" -- The alias we own
  30. property gasOurStatus : "" -- Empty, "RemoteLauncher" or "RemoteFolder"
  31. property gasOurServer : "" -- Set to server of gasOurAlias
  32. property gasOurZone : "" -- Set to zone of gasOurAlias
  33. property gasOurName : "" -- Name of original alias
  34. property gasOurVol : "" -- Name of volume alias resides on
  35. property gasOurType : "" -- If we are a RemoteLauncher, this is our file type
  36. property gasCopyLoc : {-1, -1} -- The location of the copy window
  37.  
  38. -- Remote access stuff
  39. property kraConnected : "connected" -- ARA osax strings
  40. property kraProtocol : "ARAP"
  41. property gasRemote : false -- set internally to true if volume was a RemoteAccess volume
  42. property gasRemoteCfg : "" -- Set internally to ARA config needed for this access
  43. property gasRemoteModem : "" -- Set internally to modem for RA connection
  44. property gasRemoteServer : "" -- Set internally to check if we are already connected to the correct server
  45. property gasRemoteAlias : false --Set internally to rebuild ARA with alias instead of osax
  46. property gasRemoteNum : "" -- Set internally to the telephone number of the remote machine
  47. property gasRemoteUsr : "" -- Set internally to the login user for the remote machine
  48.  
  49.  
  50. on run
  51.     if (gasOurStatus is "") then
  52.         ShowInitAlert()
  53.     else if (gasOurStatus is "RemoteLauncher") then
  54.         RunRemoteLauncher()
  55.     else if (gasOurStatus is "RemoteFolder") then
  56.         RunRemoteFolder(kasOpenWindowWhenRun)
  57.     else
  58.         beep
  59.     end if
  60. end run
  61.  
  62.  
  63. on open fsObjs
  64.     if option key down of (input state) then
  65.         if the number of items in fsObjs is not 1 then
  66.             ShowInitAlert()
  67.         else if (ShowChoice("You have the option key pressed." & return & return & ¬
  68.             "Do you wish to reinitialize this script with the object you dropped on it?")) then
  69.             SetScriptAlias(item 1 of fsObjs)
  70.         end if
  71.     else if (gasOurStatus is "") then
  72.         if the number of items in fsObjs is not 1 then
  73.             ShowInitAlert()
  74.         else
  75.             SetScriptAlias(item 1 of fsObjs)
  76.         end if
  77.     else if (gasOurStatus is "RemoteLauncher") then
  78.         (*
  79.         What we want to do here if the file dropped on us is on
  80.         the same server as our alias:
  81.         If we are a document and an application is dropped on us,
  82.         we open us with that application. If we are an application
  83.         and a document is dropped on us we open that document with
  84.         this application.
  85.         *)
  86.         -- Get the user/password
  87.         if not GetFriend(false) then return
  88.         
  89.         set cantOpen to false
  90.         set iAmApp to (gasOurType is "APPL")
  91.         
  92.         repeat with fsObj in fsObjs
  93.             set aInfo to alias info from fsObj
  94.             
  95.             if the alias server of aInfo is not gasOurServer then
  96.                 set cantOpen to true
  97.             else
  98.                 set fInfo to basic info for fsObj
  99.                 set isAnApp to (system type of fInfo is "APPL")
  100.                 
  101.                 if (iAmApp is isAnApp) then
  102.                     set cantOpen to true
  103.                 else
  104.                     if (iAmApp) then
  105.                         set appAli to gasOurAlias
  106.                         set docAli to fsObj
  107.                     else
  108.                         set appAli to fsObj
  109.                         set docAli to gasOurAlias
  110.                     end if
  111.                     
  112.                     if (not RemoteLaunchUsing(appAli, docAli)) then return
  113.                 end if
  114.             end if
  115.         end repeat
  116.         
  117.         if (cantOpen) then ShowOpenAlert()
  118.     else if (gasOurStatus is "RemoteFolder") then
  119.         set wasMounted to IsVolMounted(gasOurVol)
  120.         if (RunRemoteFolder(false)) then
  121.             repeat with fsObj in fsObjs
  122.                 try
  123.                     set gasCopyLoc to (AkuaCopy fsObj located at gasCopyLoc with resuming given «class Dest»:gasOurAlias)
  124.                 on error err
  125.                     ShowAlert("An error (" & (err as string) & ") occured copying “" & (fsObj as string) & "”. The network may have been interrupted or a disk error may have occured")
  126.                 end try
  127.             end repeat
  128.             
  129.             if (not wasMounted) then ¬
  130.                 PutAwayVol(gasOurVol)
  131.         end if
  132.     end if
  133. end open
  134.  
  135.  
  136. on RunRemoteFolder(openInFinder)
  137.     -- Get the user/password
  138.     if not GetFriend(false) then return
  139.     
  140.     set mounted to false
  141.     
  142.     -- Mount the remote volume if we weren't ARA connected.
  143.     if (not gasRemote or not gasRemoteAlias) then
  144.         try
  145.             «event ÅkuNMSVm» gasOurVol ¬
  146.                 given «class VPwd»:gasServNT, «class ZONE»:gasOurZone ¬
  147.                 , «class USER»:gasServUser ¬
  148.                 , «class PASS»:gasServPass ¬
  149.                 , «class SRVR»:gasOurServer
  150.             
  151.             set mounted to true
  152.         on error
  153.             if (CouldBeSharing(gasOurZone, gasOurServer)) then
  154.                 try
  155.                     «event ÅkuNMSVm» gasOurVol ¬
  156.                         given «class VPwd»:gasServNT, «class ZONE»:gasOurZone ¬
  157.                         , «class USER»:gasServUser ¬
  158.                         , «class PASS»:gasServPass ¬
  159.                         , «class SRVR»:gasOurServer ¬
  160.                         
  161.                 on error
  162.                     if (kasServerAlerts) then
  163.                         ShowMountAlert()
  164.                     else
  165.                         beep
  166.                     end if
  167.                     set mounted to false
  168.                 end try
  169.             else
  170.                 if (kasServerAlerts) then
  171.                     ShowMountAlert()
  172.                 else
  173.                     beep
  174.                 end if
  175.                 set mounted to false
  176.             end if
  177.         end try
  178.     end if
  179.     
  180.     if (mounted) then
  181.         try
  182.             set gfiDestFolder to «event ÅkuNResW» gasOurAlias ¬
  183.                 given «class VPwd»:gasServNT, «class USER»:gasServUser, «class PASS»:gasServPass ¬
  184.                 
  185.             
  186.             -- Tell Finder to open the alias now that it is mounted
  187.             if (openInFinder) then
  188.                 tell application kasFinder
  189.                     open gasOurAlias
  190.                     activate
  191.                 end tell
  192.             end if
  193.         on error
  194.             set mounted to false
  195.             
  196.             if (kasServerAlerts) then
  197.                 ShowAliasAlert()
  198.             else
  199.                 beep
  200.             end if
  201.         end try
  202.     end if
  203.     
  204.     return mounted
  205. end RunRemoteFolder
  206.  
  207.  
  208. on RunRemoteLauncher()
  209.     -- Get the user/password
  210.     if not GetFriend(false) then return
  211.     
  212.     if (gasOurServer is "") then
  213.         set suspect to application kasFinder
  214.     else
  215.         talk as user gasLinkUser ¬
  216.             with password gasLinkPass ¬
  217.             on server gasOurServer ¬
  218.             in AppleTalk zone gasOurZone
  219.         
  220.         set suspect to application kasFinder ¬
  221.             of machine gasOurServer ¬
  222.             of zone gasOurZone
  223.     end if
  224.     
  225.     try
  226.         -- Don't wait for a response, assume the aliases are correct?
  227.         tell suspect to open gasOurAlias
  228.     on error
  229.         if (kasServerAlerts) then
  230.             ShowConnectAlert(kasFinder)
  231.         else
  232.             beep
  233.         end if
  234.     end try
  235. end RunRemoteLauncher
  236.  
  237.  
  238. on RemoteLaunchUsing(appAli, docAli)
  239.     set aName to original name of (alias info from appAli)
  240.     
  241.     if (gasOurServer is "") then
  242.         -- Don't wait for a response, assume the aliases are correct
  243.         tell application kasFinder ¬
  244.             to open docAli given «class usin»:appAli
  245.     else
  246.         talk as user gasLinkUser ¬
  247.             with password gasLinkPass ¬
  248.             on server gasOurServer ¬
  249.             in AppleTalk zone gasOurZone
  250.         
  251.         -- Is the app running?
  252.         if (the server processes aName on server gasOurServer in AppleTalk zone gasOurZone ¬
  253.             as user name gasLinkUser with password gasLinkPass) is not "" then
  254.             try
  255.                 tell application aName of machine gasOurServer ¬
  256.                     of zone gasOurZone to open docAli
  257.             on error
  258.                 ShowConnectAlert(aName)
  259.             end try
  260.         else
  261.             try
  262.                 -- Don't wait for a response, assume the aliases are correct
  263.                 tell application kasFinder of machine gasOurServer ¬
  264.                     of zone gasOurZone to open docAli given «class usin»:appAli
  265.             on error
  266.                 if (kasServerAlerts) then
  267.                     ShowConnectAlert(kasFinder)
  268.                 else
  269.                     beep
  270.                 end if
  271.                 return false
  272.             end try
  273.         end if
  274.     end if
  275.     
  276.     return true
  277. end RemoteLaunchUsing
  278.  
  279.  
  280. on ChooseScriptAlias()
  281.     if ShowChoices("Do you wish to activate this script with a folder/volume or a file?", {"Folder", "File"}) is "File" then
  282.         set myObj to ¬
  283.             choose file with prompt "Choose a server file for this PowerScript RA"
  284.     else
  285.         set myObj to ¬
  286.             choose folder with prompt "Choose a server folder or volume for this PowerScript RA"
  287.     end if
  288.     
  289.     SetScriptAlias(myObj)
  290. end ChooseScriptAlias
  291.  
  292.  
  293. on SetScriptAlias(aliasObj)
  294.     -- My Path
  295.     set myPath to (path to me)
  296.     
  297.     -- Grab an alias
  298.     set gasOurAlias to aliasObj
  299.     set aInfo to alias info from aliasObj
  300.     set fInfo to basic info for aliasObj
  301.     
  302.     -- Save the info we need
  303.     set gasOurServer to alias server of aInfo
  304.     set gasOurZone to alias zone of aInfo
  305.     set gasOurVol to alias volume of aInfo
  306.     set gasOurName to original name of aInfo
  307.     
  308.     -- Remote info
  309.     set gasRemoteNum to ARA number of aInfo
  310.     set gasRemoteUsr to ARA user of aInfo
  311.     set gasRemotePwd to ARA password of aInfo
  312.     
  313.     set gasOurType to system type of fInfo
  314.     
  315.     set newName to gasOurName -- Start with name of original item
  316.     
  317.     -- What will we be - a mounter or a launcher?
  318.     if (catalog kind of fInfo) is a folder then
  319.         set gasOurStatus to "RemoteFolder"
  320.         set gasServNeed to true
  321.     else
  322.         set gasOurStatus to "RemoteLauncher"
  323.         set gasLinkNeed to true
  324.         set newName to kasPrefixLauncher & newName
  325.     end if
  326.     
  327.     -- Try to set our name to dropped name
  328.     try
  329.         collate myPath renaming it to newName
  330.     on error
  331.         -- If we can't use the original name, try an appendage :)
  332.         try
  333.             collate myPath renaming it to newName & kasAppendage
  334.         on error
  335.             beep
  336.         end try
  337.     end try
  338.     
  339.     -- Get the user/password
  340.     GetFriend(false)
  341.     
  342.     -- Check ARA connection
  343.     set gasRemote to IsRemoteAccessed()
  344.     
  345.     if (gasRemote) then
  346.         WantRemoteAccess()
  347.         if (gasRemoteAlias) then ¬
  348.             GetOneFriend(false, false) -- Need to preflight server if we will be resolving the alias for the ARA connection
  349.     end if
  350.     
  351.     -- Set our icon to dropped icon
  352.     set ourIcon to (the icon for aliasObj)
  353.     set the icon of myPath to ourIcon
  354.     
  355.     try
  356.         tell application "Finder" to update myPath -- Double dose?
  357.     on error
  358.         beep
  359.     end try
  360. end SetScriptAlias
  361.  
  362.  
  363. on GetFriend(override)
  364.     set gasLinkUser to kasLinkUserDft
  365.     set gasLinkPass to kasLinkPassDft
  366.     set gasServUser to kasServUserDft
  367.     set gasServPass to kasServPassDft
  368.     set gasServNT to kasServNTDft
  369.     
  370.     if (gasOurServer is "") then -- Local?
  371.         set gasLinkSet to true
  372.         set gasServSet to true
  373.     else
  374.         -- Build ARA connection?
  375.         if (gasRemote and not gasRemoteAlias) then
  376.             if not BuildRemoteAccess() then return false
  377.         end if
  378.         
  379.         -- Get linking (and server) user?
  380.         if (gasLinkNeed) then
  381.             GetOneFriend(true, override)
  382.             if (gasRemote and gasRemoteAlias) then ¬
  383.                 GetOneFriend(false, override)
  384.         end if
  385.         
  386.         -- Get server user?
  387.         if (gasServNeed) then GetOneFriend(false, override)
  388.     end if
  389.     return true
  390. end GetFriend
  391.  
  392.  
  393. on GetOneFriend(isLink, override)
  394.     if (isLink) then
  395.         set userMode to "linking"
  396.         if (gasLinkSet) then
  397.             set defUser to gasLinkUser
  398.             set defPass to gasLinkPass
  399.         end if
  400.         set defNT to kasServNTDft
  401.         set passButtons to {"Cancel", "OK"}
  402.         set passButton to 2
  403.     else
  404.         set userMode to "sharing"
  405.         if (gasServSet) then
  406.             set defUser to gasServUser
  407.             set defPass to gasServPass
  408.             set defNT to gasServNT
  409.         end if
  410.         set passButtons to {"Cancel", "NT Password…", "OK"}
  411.         set passButton to 3
  412.     end if
  413.     
  414.     set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
  415.     
  416.     if (override or usrPwd is {}) then
  417.         set chosen to display dialog ¬
  418.             "Enter the friendly " & userMode & ¬
  419.             " user's name for the server \"" & gasOurServer ¬
  420.             & "\"…" default answer defUser ¬
  421.             default button 2 with icon note
  422.         
  423.         if (the button returned of chosen is "OK") then
  424.             set defUser to the text returned of chosen
  425.         else
  426.             return
  427.         end if
  428.         
  429.         set chosen to display dialog ¬
  430.             "Enter the friendly " & userMode & ¬
  431.             " user's password…" buttons passButtons ¬
  432.             default answer defPass default button passButton with icon note
  433.         
  434.         if (the button returned of chosen is not "Cancel") then
  435.             set defPass to the text returned of chosen
  436.         else
  437.             return
  438.         end if
  439.         
  440.         if (the button returned of chosen is "NT Password…") then
  441.             set chosen to display dialog ¬
  442.                 "Enter the volume password for Windoze NT…" default answer ¬
  443.                 defNT default button 2 with icon note
  444.             
  445.             if (the button returned of chosen is not "Cancel") then
  446.                 set gasServNT to the text returned of chosen
  447.             else
  448.                 return
  449.             end if
  450.         end if
  451.         
  452.         -- Save encrypted user/pass for future access
  453.         KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
  454.     else
  455.         set defUser to item 1 of usrPwd
  456.         set defPass to item 2 of usrPwd
  457.         set defNT to item 3 of usrPwd
  458.     end if
  459.     
  460.     if (isLink) then
  461.         set gasLinkSet to true
  462.         set gasLinkUser to defUser
  463.         set gasLinkPass to defPass
  464.     else
  465.         set gasServSet to true
  466.         set gasServUser to defUser
  467.         set gasServPass to defPass
  468.         set gasServNT to defNT
  469.     end if
  470. end GetOneFriend
  471.  
  472.  
  473. on PutAwayVol(volName)
  474.     -- Volume
  475.     try
  476.         set vAlias to (vol alias of (the volume info of volume named volName))
  477.         tell application "Finder"
  478.             update vAlias
  479.             pause for 2 with seconds timing -- Give some time to the Finder?
  480.             put away item vAlias
  481.         end tell
  482.     on error
  483.         beep
  484.     end try
  485. end PutAwayVol
  486.  
  487.  
  488. on IsVolMounted(volName)
  489.     -- Volume
  490.     try
  491.         set x to (volName & ":") as alias
  492.         return true
  493.     on error
  494.         return false
  495.     end try
  496. end IsVolMounted
  497.  
  498.  
  499. property sasShareLoc : {-1, -1}
  500.  
  501. on CouldBeSharing(servZone, servName)
  502.     GetOneFriend(true, false) -- Get linking user
  503.     
  504.     talk as user gasLinkUser ¬
  505.         with password gasLinkPass ¬
  506.         on server servName ¬
  507.         in AppleTalk zone servZone
  508.     
  509.     try
  510.         set isOn to («class fshr» ¬
  511.             of application kasFinder ¬
  512.             of machine servName ¬
  513.             of zone servZone)
  514.         
  515.         if (not isOn) then
  516.             set «class fshr» of application kasFinder ¬
  517.                 of machine servName ¬
  518.                 of zone servZone to true
  519.             
  520.             set inf to (display info titled ¬
  521.                 "Wait for Sharing" message ¬
  522.                 (servZone & ":" & servName) ¬
  523.                     located at sasShareLoc)
  524.             
  525.             set waitSecs to 333
  526.             
  527.             repeat while not («class fshr» of application kasFinder ¬
  528.                 of machine servName ¬
  529.                 of zone servZone)
  530.                 display info inf message ¬
  531.                     ("Wait another " & waitSecs & " seconds") at line 2
  532.                 pause for 2 with seconds timing
  533.                 set waitSecs to waitSecs - 2
  534.                 if (waitSecs < 1) then exit repeat
  535.             end repeat
  536.             
  537.             if («class fshr» of application kasFinder ¬
  538.                 of machine servName ¬
  539.                 of zone servZone) then
  540.                 display info inf message ¬
  541.                     "It is up!" at line 2
  542.             else
  543.                 display info inf message ¬
  544.                     "Can't get it up!" at line 2
  545.                 beep
  546.             end if
  547.             
  548.             set sasShareLoc to screen location of ¬
  549.                 (display info inf with disposal)
  550.             
  551.             return («class fshr» of application ¬
  552.                 kasFinder of machine servName of zone servZone)
  553.         end if
  554.     on error errStr
  555.         if (errStr contains "-911") then
  556.             GetOneFriend(true, true)
  557.             return CouldBeSharing()
  558.         end if
  559.     end try
  560.     
  561.     return false
  562. end CouldBeSharing
  563.  
  564.  
  565. on ShowAccessAlert()
  566.     ShowServerAlert("The remote access connection for the item on " & gasOurServer ¬
  567.         & " in zone " & gasOurZone & " failed to be made.")
  568. end ShowAccessAlert
  569.  
  570.  
  571. on ShowRemoteAlert()
  572.     ShowServerAlert("Couldn't find remote item on " & gasOurServer ¬
  573.         & " in zone " & gasOurZone & ¬
  574.         " due to ARA connection problems or changes in the remote zone or on the remote volume.")
  575. end ShowRemoteAlert
  576.  
  577.  
  578. on ShowAliasAlert()
  579.     if ShowChoices("Couldn't resolve alias for " & gasOurName & ¬
  580.         " on " & gasOurVol & " from machine " & gasOurServer & ¬
  581.         "." & return & return & "Would you like to reset it?", ¬
  582.         {"Refind item", "No"}) is not "No" then ¬
  583.         ChooseScriptAlias()
  584. end ShowAliasAlert
  585.  
  586.  
  587. on ShowMountAlert()
  588.     if (gasRemote) then
  589.         ShowRemoteAlert()
  590.     else
  591.         ShowServerAlert("Couldn't mount volume " & gasOurVol & ¬
  592.             " from " & gasOurServer ¬
  593.             & " in zone " & gasOurZone)
  594.     end if
  595. end ShowMountAlert
  596.  
  597.  
  598. on ShowConnectAlert(appName)
  599.     ShowServerAlert("Couldn't connect to " & appName & " on " & ¬
  600.         gasOurServer & " in zone " & gasOurZone)
  601. end ShowConnectAlert
  602.  
  603.  
  604. on ShowServerAlert(msg)
  605.     if ShowChoices(msg, {"Reenter Password", "OK"}) ¬
  606.         is not "OK" then ¬
  607.         GetFriend(true)
  608. end ShowServerAlert
  609.  
  610.  
  611. on ShowInitAlert()
  612.     if ShowChoices("This script must first be activated by dropping exactly one item on it." & ¬
  613.         return & return & "Please see the information file that accompanied it.", ¬
  614.         {"Activate", "OK"}) is not "OK" then ¬
  615.         ChooseScriptAlias()
  616. end ShowInitAlert
  617.  
  618.  
  619. on ShowOpenAlert()
  620.     ShowAlert("This script is currently in Launcher mode and can thus not process any files dropped on it." & ¬
  621.         return & return & "To reconfigure the script, open it with ScriptEditor and save it.")
  622. end ShowOpenAlert
  623.  
  624.  
  625. on ShowAlert(msgStr)
  626.     if (kasAllowAlerts) then ¬
  627.         display dialog msgStr buttons {"Damn!"} ¬
  628.             default button 1 with icon caution
  629. end ShowAlert
  630.  
  631.  
  632. on ShowChoice(msgStr)
  633.     return (ShowChoices(msgStr, {"No", "Yes"}) is "Yes")
  634. end ShowChoice
  635.  
  636.  
  637. on ShowChoices(msgStr, choices)
  638.     set choice to ¬
  639.         display dialog msgStr buttons choices ¬
  640.             default button (number of items of choices) ¬
  641.             with icon stop
  642.     return (button returned of choice)
  643. end ShowChoices
  644.  
  645.  
  646. property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
  647. property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
  648.  
  649. on KeyChainLookUp(zoneName, serverName, isLinking)
  650.     set prefType to "πSRV"
  651.     if (isLinking) then set prefType to "πLNK"
  652.     
  653.     try
  654.         set myKeyData to load preference of type prefType ¬
  655.             named (zoneName & ":" & serverName) ¬
  656.             in file named kasPrefsFileName
  657.     on error
  658.         return {}
  659.     end try
  660.     
  661.     return (encrypt the data myKeyData ¬
  662.         with password kasKeyChainPassword)
  663. end KeyChainLookUp
  664.  
  665.  
  666. on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
  667.     set myKey to encrypt the data {usr, pwd, ntPwd} ¬
  668.         with password kasKeyChainPassword
  669.     
  670.     set prefType to "πSRV"
  671.     if (isLinking) then set prefType to "πLNK"
  672.     
  673.     save preference myKey of type prefType ¬
  674.         named (zoneName & ":" & serverName) ¬
  675.         in file named kasPrefsFileName
  676. end KeyChainSave
  677.  
  678.  
  679. on IsRemoteAccessed()
  680.     try
  681.         set araStats to (RA status)
  682.     on error
  683.         return false
  684.     end try
  685.     
  686.     return ((state of araStats) is kraConnected) ¬
  687.         and ((protocol of araStats) is kraProtocol)
  688. end IsRemoteAccessed
  689.  
  690.  
  691. on WantRemoteAccess()
  692.     set gasRemoteAlias to true
  693.     
  694.     if kasJustDoIt or ¬
  695.         (ShowChoice("PowerScript noticed that an ARA connection is active." & return & return & ¬
  696.             "Do you wish the connection to be built before searching for the item?" & return & return & ¬
  697.             "(If you answer No, the ARA connection may be made by resolving the alias.)")) then
  698.         
  699.         -- Get the ARA config for the alias
  700.         set configs to RA configurations whose numbers are gasRemoteNum ¬
  701.             whose users are gasRemoteUsr
  702.         
  703.         if (the number of items in configs) > 0 then
  704.             set gasRemoteCfg to item 1 of (item 1 of configs) -- The name of the config to use
  705.             set gasRemoteServer to server name of (RA status)
  706.             set gasRemoteAlias to false
  707.             set gasRemoteModem to «event ÅkuNMdmÇ»
  708.         else
  709.             ShowAlert("Can't find RA configuration for the current connection?!?")
  710.         end if
  711.     end if
  712. end WantRemoteAccess
  713.  
  714.  
  715. on BuildRemoteAccess()
  716.     set araIsOn to IsRemoteAccessed()
  717.     
  718.     if (araIsOn) then
  719.         -- Connected to correct server?
  720.         if (server name of (RA status)) is gasRemoteServer then
  721.             return true
  722.         else
  723.             RA disconnect
  724.             set araIsOn to IsRemoteAccessed()
  725.         end if
  726.     end if
  727.     
  728.     if (not araIsOn) then
  729.         -- Save current config, set it to ours, connect, set it back
  730.         set saveConfig to RA configuration gasRemoteCfg
  731.         set saveModem to «event ÅkuNMdmÇ» gasRemoteModem
  732.         
  733.         try
  734.             RA connect
  735.         on error
  736.             beep
  737.         end try
  738.         
  739.         RA configuration saveConfig
  740.         «event ÅkuNMdmÇ» saveModem
  741.         
  742.         if (IsRemoteAccessed()) then return true
  743.     end if
  744.     
  745.     ShowAccessAlert()
  746.     return false
  747. end BuildRemoteAccess
  748.